package com.atguigu05.communication;

/**
 * ClassName: Print
 * Package: com.atguigu05.communication
 * Description:
 *
 * @Author BuTang
 * @Create 2023/5/16 20:30
 * @Version 1.0
 */
public class Print implements Runnable {
    public static int start = 0;

    @Override
    public void run() {

        while (start < 100) {
            synchronized (this) {
                try {
                    Thread.sleep(500);
                    notify();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName() + "--" + start);
                start++;
                try {
                wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
                }
//

            }
        }
    }

    class PrintTest {
        public static void main(String[] args) {
            Print p = new Print();
            Thread a = new Thread(p);
            Thread b = new Thread(p);
            a.setName("线程1");
            b.setName("线程2");

            a.start();
            b.start();

        }
    }




